package com.loubobooo.personal.blog.service.impl;

import com.loubobooo.personal.blog.entity.Link;
import com.loubobooo.personal.blog.entity.vo.LinkVO;
import com.loubobooo.personal.blog.mapper.LinkMapper;
import com.loubobooo.personal.blog.mapper.custom.LinkMapperCustom;
import com.loubobooo.personal.blog.service.LinkService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service public class LinkServiceImpl implements LinkService {

    @Autowired private LinkMapperCustom linkMapperCustom;

    @Autowired private LinkMapper linkMapper;

    @Override public Integer countLink(Integer status)  {
        return linkMapperCustom.countLink(status);
    }

    @Override public List<LinkVO> listLink(Integer status) {
        return linkMapperCustom.listLink(status);
    }

    @Override public void insertLink(Link link) {
        linkMapper.insertSelective(link);
    }

    @Override public void deleteLink(Integer id) {
        linkMapper.deleteByPrimaryKey(id);
    }

    @Override public void updateLink(Link link) {
        linkMapper.updateByPrimaryKeySelective(link);
    }

    @Override public LinkVO getLinkById(Integer id) {
        Link link = linkMapper.selectByPrimaryKey(id);
        LinkVO linkVO = new LinkVO();
        BeanUtils.copyProperties(link, linkVO);
        return linkVO;
    }

}
